#include<vector>
using namespace std;

struct TreeNode {
      int val;
     TreeNode *left;
      TreeNode *right;
     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 };


class Solution {
public:
    bool isSubStructure(TreeNode* A, TreeNode* B) {
        if (A==NULL || B==NULL) return false;

        //递归当前节点
        if(dfs(A, B)) return true;

        //递归左节点
        if(isSubStructure(A->left, B)) return true;

        //递归右节点
        if(isSubStructure(A->right, B)) return true;

        return false;
    }
    bool dfs(TreeNode* A, TreeNode* B){
        //中止的三个条件
        if(B==NULL)return true;
        if(A==NULL)return false;
        if(A->val!=B->val)return false;

        return dfs(A->left, B->left) && dfs(A->right, B->right);
    }


};
